﻿using System;
using System.Collections.Generic;
using System.Text;

using YouHP.Model;
using YouHP.DALFactory;
using YouHP.Utility;
namespace YouHP.BLL
{
    public class NewsInfoBLL
    {
        #region Singleton
        static NewsInfoBLL _Instance;
        public static NewsInfoBLL Instance
        {
            get
            {
                if (_Instance == null)
                {
                    _Instance = new NewsInfoBLL();
                }
                return _Instance;
            }
        }
        #endregion

        public bool AddNews(NewsInfo info)
        {
            return DataAccess.NewsInfoDAL.AddNewsBulletin(info);
        }

        public bool DeleteNewsInfo(int id)
        {
            return DataAccess.NewsInfoDAL.DeleteNewsBulletin(id);
        }
        public bool UpdateNewsInfo(NewsInfo info)
        {
            return DataAccess.NewsInfoDAL.UpdateNewsBulletin(info);
        }

        public NewsInfo GetNewsInfoByID(int id)
        {
            return DataAccess.NewsInfoDAL.GetNewsBulletinById(id);
        }

        public List<NewsInfo> GetNewsInfoList()
        {
            return DataAccess.NewsInfoDAL.GetNewsList();
        }

        public List<NewsInfo> GetBulletinInfoList()
        {
            return DataAccess.NewsInfoDAL.GetBullentinList();
        }

        /*新闻分页检索, 输出符合条件的总新闻条数*/
        // isQueryNews == true 表示获取新闻列表
        // isQueryNews == false 表示获取公告列表
        public List<NewsInfo> GetNewsInfoList(bool isQueryNews, int pageSize, int pageIndex, out int count)
        {
            string condStr = string.Format("[IsNews]={0}", isQueryNews? 1: 0);
            string orderStr = string.Format("[LastUpdateTime] DESC");
            return DataAccess.NewsInfoDAL.GetNewsInfoList(pageSize, pageIndex, condStr, orderStr, out count);
        }

        #region NewsComment

        public bool AddNewsComment(NewsComment newsComment)
        {
            return DataAccess.NewsCommentsDAL.AddNewsComment(newsComment);
        }

        public NewsComment GetNewsCommentByID(int id)
        {
            return DataAccess.NewsCommentsDAL.GetNewsComment(id);
        }

        public List<NewsComment> GetNewsCommentList(int newsID)
        {
            return DataAccess.NewsCommentsDAL.GetNewsCommentList(newsID);
        }

        public bool UpdateNewsComment(NewsComment newsComment)
        {
            return DataAccess.NewsCommentsDAL.UpdateNewsComment(newsComment);
        }

        public bool DeleteNewsComment(int id)
        {
            return DataAccess.NewsCommentsDAL.DeleteNewsComment(id);
        }

        public int GetNewsCommentCount(int newsID)
        {
            return DataAccess.NewsCommentsDAL.GetNewsCommentCount(newsID);
        }


        #endregion

    }
}
